package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.util.ApplicablePlatformEnum;
import com.frogs.system.util.OpenPlatformEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

/**
 * 注册用请求参数类
 *
 * @author lijian
 * @version 2014年4月8日 - 下午8:06:03
 */
public class UserAccountInfoAutoRegisterRequest extends Request {

	/**
	 * 第三方应用用户标识
	 */
	private String openId;
	
	/**
	 * 手机号码
	 */
	private String phone;
	
	/**
	 * 邮箱
	 */
	private String email;
	
	/**
	 * 适用范围
	 */
	private int applicablePlatformId;
	
	private int openPlatformId;
	
	private String ip;
	
	private String expandCode;
	
	@Override
	public void parse(HttpServletRequest request) {
		
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
		this.openId = requestInfo.getParameter(ApiUrlParamEnum.openId.getParamName(), "");
		this.phone = requestInfo.getParameter(ApiUrlParamEnum.phone.getParamName(), "");
		this.email = requestInfo.getParameter(ApiUrlParamEnum.email.getParamName(), "");
		this.applicablePlatformId = requestInfo.getIntParameter(ApiUrlParamEnum.applicablePlatformId.getParamName(), ApplicablePlatformEnum.WECHAT.getId());
		this.expandCode = requestInfo.getParameter(ApiUrlParamEnum.expandCode.getParamName(), "-");
		this.openPlatformId = requestInfo.getIntParameter(ApiUrlParamEnum.openPlatformId.getParamName(), OpenPlatformEnum.CHUNYUYISHENG.getId());
		this.ip = requestInfo.getParameter(ApiUrlParamEnum.ip.getParamName(), requestInfo.getUserIp());
		
		if (!StringUtil.isEmpty(phone) && !StringUtil.isMobilePhone(phone)) {
			throw new RequestIllegalException("手机号码格式有误");
		}
		if (!StringUtil.isEmpty(email) && !StringUtil.isEmail(email)) {
			throw new RequestIllegalException("邮箱格式有误");
		}
	}

	public String getOpenId() {
		return openId;
	}

	public void setOpenId(String openId) {
		this.openId = openId;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public int getApplicablePlatformId() {
		return applicablePlatformId;
	}

	public void setApplicablePlatformId(int applicablePlatformId) {
		this.applicablePlatformId = applicablePlatformId;
	}

	public String getExpandCode() {
		return expandCode;
	}

	public void setExpandCode(String expandCode) {
		this.expandCode = expandCode;
	}

	public String getIp() {
		return ip;
	}
	
	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public int getOpenPlatformId() {
		return openPlatformId;
	}

	public void setOpenPlatformId(int openPlatformId) {
		this.openPlatformId = openPlatformId;
	}
}
